import $ from 'jquery'
class Scroll{
  constructor(options) {
    try {
      this.wrapperEl = $(options.wrapperEl);
      this.$el = $(options.el);
      this.el = this.$el[0];
      this.dis = options.dis || 300;
      this.callback = options.callback;
      this._init()
    } catch (error) {
      console.log(error);
    }
  }
  _init() {
    this._bingScroll();
  }
  _bingScroll(){
    this.wrapperEl.on('scroll', () => {
      this._scrollFn()
    });
  }
  _scrollFn() {
    let wrapperHeight = this.wrapperEl.height();
    let elHeight = this.$el.height();
    let elScrollTop = this.wrapperEl.scrollTop();
    if (elScrollTop + wrapperHeight + this.dis >= elHeight) {
      this.callback();
    }
  }
  unbind() {
    this.wrapperEl.off('scroll');
    console.log('off scroll');
    
  }
}

export default Scroll;